package com.medical.system.controller;

import com.medical.system.common.Result;
import com.medical.system.model.Scheduling;
import com.medical.system.service.SchedulingService;
import com.medical.system.vo.SchedulingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "排班控制器")
@RestController
@RequestMapping("/admin/system/scheduling")
public class SchedulingController {

    @Autowired
    private SchedulingService schedulingService;

    @ApiOperation("分页查询")
    @GetMapping("/{page}/{limit}")
    public Result queryScheduling(@PathVariable Long page, @PathVariable Long limit, SchedulingVo schedulingVo) {
        return this.schedulingService.selectPage(page, limit, schedulingVo);
    }

    @ApiOperation("添加排班")
    @PostMapping("/addScheduling")
    public Result addScheduling(@RequestBody Scheduling scheduling) {
        if (scheduling.getDoctor() == null || "".equals(scheduling.getDoctor())) {
            return Result.build(null, 210, "医生不能为空");
        }
        return this.schedulingService.addScheduling(scheduling);
    }

    @ApiOperation("修改排班")
    @PostMapping("/updateScheduling")
    public Result updateScheduling(@RequestBody Scheduling scheduling) {
        if (scheduling.getId() == null || "".equals(scheduling.getId())) {
            return Result.build(null, 210, "医生不能为空");
        }
        return this.schedulingService.updateScheduling(scheduling);
    }

    @ApiOperation("删除排班")
    @PostMapping("/remove/{id}")
    public Result removeScheduling(@PathVariable Long id) {
        if (id == null || "".equals(id)) {
            return Result.build(null, 210, "参数异常");
        }
        return this.schedulingService.deleteScheduling(id);
    }
    @ApiOperation("根据id查询排班")
    @GetMapping("/byId/{id}")
    public Result findById(@PathVariable Integer id) {
        if (id == null || "".equals(id)) {
            return Result.build(null, 210, "参数异常");
        }
        return this.schedulingService.selectSchedulingById(id);
    }
}
